#ifndef C3DS_LOADER__
#define C3DS_LOADER__

#include <cstdlib>
#include <GL/glut.h>
#include "CVector.h"
#include "CTgaLoader.h"

extern class CFont CstdFont;

struct BoundingBox
{
       CVector3 min;
       CVector3 max;
       CVector3 CrossProducts[3];
};

struct BoundingSphere
{
       double radius;
       CVector3 position;
};

struct UVCoord2
{
       float u;
       float v;
};

struct POLY_type
{
       unsigned short a,b,c;
};

struct MESH_Object
{
   char name[30];
   unsigned num_vertices;
   unsigned num_polygons;
   unsigned num_texCoord;
   CVector3 * vertex;
   POLY_type * polygons;
   UVCoord2 * texCoord; 
   float diffuse_color[3]; 
};

//////////////////////////////////////
class C3DModel
{
private:
   FILE * pFile;                      // .3ds file
   unsigned short num_obj;            // the number of objects in the mesh
   MESH_Object * mesh_objs;           // structure for objects in the mesh
   char * texture_file;               // file used for texturing
   CTGALoader TGA_texture;            // image container
   unsigned int list;                 // display list
   unsigned int texture_ID;			  // saves the ID of the texture
   
protected:
   CVector3 position;
   double x_ang;
   double y_ang;
   double z_ang;
   
   BoundingBox boundingBox;
   BoundingSphere boundingSphere;
   
public:
   C3DModel();
   C3DModel(const C3DModel & model);
   C3DModel(char * mesh_file) {loadMesh(mesh_file);}
   C3DModel(char * mesh_file, char * texture_file) {loadMesh(mesh_file); loadTexture(texture_file);}
   bool loadMesh(char * file);
   bool loadTexture(char * file);
   void clearMesh(void);
   void clearTexture(void);
   void genList(void);
   unsigned int getTextureID() {return TGA_texture.ID;}
   unsigned int getList(void) {return list;}
   void callList() {glCallList(list);}
   void drawMesh(void);
   void calculateBBox(void);
   void calculateBSphere(void);
   void drawBBox();
   void drawBSphere();
   
   BoundingBox getBBox() {return boundingBox;} // put a check to see if boundings exist
   BoundingSphere getBSphere(void) {return boundingSphere;}
   CVector3 getPosition() {return position;}
   void setPosition(CVector3 pos) {position=pos;}
   double getAngleX() {return x_ang;}
   double getAngleY() {return y_ang;}
   void changePosition(double x, double y, double z);
   void changeAngle(double x, double y, double z =0);
   void setAngleX(double x){x_ang = x;}
   void setAngleY(double y){y_ang = y;}

   C3DModel & operator=(const C3DModel & model);   
   ~C3DModel();
};




#endif
